package com.ruoyi.framework.web.service.proxy;

import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.ServiceException;
import org.springframework.security.core.Authentication;

import java.util.Objects;

/**
 * @author ab785
 * createTime: 2021-10-24.
 * description: 通用验证码校验
 */
public abstract class AbstractCodeLoginFlow extends LoginFlow {


    @Override
    Authentication doLogin(LoginBody loginBody) {
        Authentication authenticate = userNameDirectLogin(loginBody);
        //校验手机号
        LoginUser loginUser = (LoginUser) authenticate.getPrincipal();
        if (!Objects.equals(loginUser.getUser().getPhonenumber(), loginBody.getPhone())) {
            throw new ServiceException("用户名与所传入的手机号不匹配");
        }
        return authenticate;
    }
}
